<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>办公用品申请</title>
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/base.css" />
		<link rel="stylesheet"
			href="${pageContext.request.contextPath }/css/info-reg.css" />
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/jquery.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/common.js"></script>
		<script type="text/javascript"
			src="${pageContext.request.contextPath }/js/WdatePicker.js"></script>
	</head>
	<body>
		<div class="title">
			<h2> 
				办公物品申请 
			</h2>
		</div>
		<form action="${pageContext.request.contextPath }/ComMethod.action?method=insertApplyCom" method="post">
			<div class="main">
				<p class="long-input ue-clear">
					<label>
						申请人：
					</label>
					<input type="hidden" value="${login_User.userId }" name="id">
					<input type="text" value="${login_User.userName }" readonly="readonly" name="username"/>
				</p>
				<p class="long-input ue-clear">
					<label>
						申请人部门：
					</label>
					<input type="text" value="${requestScope.deptname }" readonly="readonly" name="userdept"/>
				</p>
				<p class="long-input ue-clear">
					<label>
						申请物品：
					</label>
					<select onchange="initComData()" id="comtype" name="comtype">
						<option>请选择</option>
						<option>办公用品</option>
						<option>公共资源</option>
					</select>
					&nbsp;
					<select id="comresource" name="comid" onchange="getComname()">
						<option>请选择</option>
					</select>
				</p>
				<input type="hidden" id="comname" name="comname">
				<p class="long-input ue-clear">
					<label>
						申请数量：
					</label>
					<input type="text" placeholder="请输入数量" name="num"/>
				</p>
				<p class="long-input ue-clear">
					<label>
						使用时间：
					</label>
					
					<input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" placeholder="开始时间" name="starttime"/>
					<span class="line">-&nbsp;&nbsp;&nbsp;</span>
					<input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" placeholder="结束时间" name="endtime"/>
					&nbsp;&nbsp;&nbsp;&nbsp;申请办公物品无需设置使用时间
					
				</p>
			</div>
			<div class="btn ue-clear">
				<input type="submit" value="提交申请"/>
				<input type="reset" />
			</div>
		</form>
	</body>
	<script type="text/javascript">
	function getComname(){
		
		var obj = document.getElementById("comname");

		var comobj = document.getElementById("comresource");
		var index = comobj.selectedIndex;
		obj.value=comobj.options[index].text;
	}

	function createXMLHttpRequest() {
		var xmlReq = new XMLHttpRequest();
		return xmlReq;
	}
	var xmlHttpReq;
	function initComData() {
		var url = "${pageContext.request.contextPath }/getComNameServlet";
		//1.创建异步请求对象
		xmlHttpReq = createXMLHttpRequest();
		//2.建立到服务器的新请求
		xmlHttpReq.open("post", url, true);
		//3.设定服务器响应回调方法：告诉服务器数据返回后应该怎么处理
		xmlHttpReq.onreadystatechange = addComData;//指定回调函数
		var aaaaa = document.getElementById("comtype").value;
		var params ="comtype11="+ aaaaa;
		//4.发送异步请求
		xmlHttpReq.setRequestHeader("Content-type","application/x-www-form-urlencoded");
		xmlHttpReq.send(params);
	}
	function addComData() {
		if (xmlHttpReq.readyState == 4) {
			if (xmlHttpReq.status == 200) {
				var xmldoc = xmlHttpReq.responseXML;
				ComSelect(xmldoc);
			}
		}
	}
	function ComSelect(xmldoc) {
		var selObj = document.getElementById("comresource");
		var idArray = xmldoc.getElementsByTagName("id");
		var nameArray = xmldoc.getElementsByTagName("name");
		selObj.length = 1;
		for ( var i = 0; i < idArray.length; i++) {
			var optObj = document.createElement("option");
			optObj.value = idArray[i].innerHTML;
			optObj.text = nameArray[i].innerHTML;
			selObj.appendChild(optObj);
		}
	}
</script>
</html>
